home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -screenplay- / hd_installers / -whdload- / whdload_dev / include / whdload.i < prev    next >
Text File  |  2000-02-28  |  16KB  |  478 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Module.    whdload.i
  3. ;  :Contens.    include file for WHDLoad and Slaves
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@whdload.org
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: whdload.i 10.5 2000/01/25 22:08:51 jah Exp jah $
  8. ;  :History.    11.04.99 marcos moved to separate include file
  9. ;        08.05.99 resload_Patch added
  10. ;  :Copyright.    © 1996-2000 Bert Jahn, All Rights Reserved
  11. ;  :Language.    68000 Assembler
  12. ;  :Translator.    Barfly 2.9, Asm-Pro 1.16, PhxAss 4.38
  13. ;---------------------------------------------------------------------------*
  14.  
  15.  IFND WHDLOAD_I
  16. WHDLOAD_I=1
  17.  
  18.     IFND    EXEC_EXECBASE_I
  19.     INCLUDE    exec/execbase.i
  20.     ENDC
  21.     IFND    EXEC_TYPES_I
  22.     INCLUDE    exec/types.i
  23.     ENDC
  24.     IFND    GRAPHICS_MODEID_I
  25.     INCLUDE    graphics/modeid.i
  26.     ENDC
  27.     IFND    UTILITY_TAGITEM_I
  28.     INCLUDE    utility/tagitem.i
  29.     ENDC
  30.  
  31. ;=============================================================================
  32. ;    misc
  33. ;=============================================================================
  34.  
  35. SLAVE_HEADER    MACRO
  36.         moveq    #-1,d0
  37.         rts
  38.         dc.b    "WHDLOADS"
  39.         ENDM
  40.  
  41. ;=============================================================================
  42. ;    return-values for termination (resload_Abort)
  43. ;=============================================================================
  44.  
  45. TDREASON_OK        = -1    ;normal termination
  46. TDREASON_DOSREAD    = 1    ;error caused by resload_ReadFile
  47.                 ; primary   = dos errorcode
  48.                 ; secondary = file name
  49. TDREASON_DOSWRITE    = 2    ;error caused by resload_SaveFile or
  50.                 ;resload_SaveFileOffset
  51.                 ; primary   = dos errorcode
  52.                 ; secondary = file name
  53. TDREASON_DEBUG        = 5    ;cause WHDLoad to make a coredump and quit
  54.                 ; primary   = PC (writing to dump files)
  55.                 ; secondary = SR (writing to dump files)
  56. TDREASON_DOSLIST    = 6    ;error caused by resload_ListFiles
  57.                 ; primary   = dos errorcode
  58.                 ; secondary = directory name
  59. TDREASON_DISKLOAD    = 7    ;error caused by resload_DiskLoad
  60.                 ; primary   = dos errorcode
  61.                 ; secondary = disk number
  62. TDREASON_DISKLOADDEV    = 8    ;error caused by resload_DiskLoadDev
  63.                 ; primary   = trackdisk errorcode
  64. TDREASON_WRONGVER    = 9    ;an version check (e.g. crc16) has detected an
  65.                 ;unsupported version of the installed program
  66. TDREASON_OSEMUFAIL    = 10    ;error in the OS emulation module
  67.                 ; primary   = subsystem (e.g. "exec.library")
  68.                 ; secondary = error number (e.g. _LVOAllocMem)
  69. ; version 7
  70. TDREASON_REQ68020    = 11    ;installed program requires a MC68020
  71. TDREASON_REQAGA        = 12    ;installed program requires the AGA chip set
  72. TDREASON_MUSTNTSC    = 13    ;installed program needs NTSC videomode to run
  73. TDREASON_MUSTPAL    = 14    ;installed program needs PAL videomode to run
  74. ; version 8
  75. TDREASON_MUSTREG    = 15    ;WHDLoad must be registered
  76. TDREASON_DELETEFILE    = 27    ;error caused by resload_DeleteFile
  77.                 ; primary   = dos errorcode
  78.                 ; secondary = file name
  79.  
  80. ;=============================================================================
  81. ; tagitems for the resload_Control function
  82. ;=============================================================================
  83.  
  84.  ENUM    TAG_USER+$8000000
  85.  EITEM    WHDLTAG_ATTNFLAGS_GET    ;get info about current CPU/FPU/MMU
  86.  EITEM    WHDLTAG_ECLOCKFREQ_GET    ;get frequency custom chips operate on
  87.  EITEM    WHDLTAG_MONITOR_GET    ;get the used monitor/video mode
  88.                 ;(NTSC_MONITOR_ID or PAL_MONITOR_ID)
  89.  EITEM    WHDLTAG_Private1
  90.  EITEM    WHDLTAG_Private2
  91.  EITEM    WHDLTAG_Private3
  92.  EITEM    WHDLTAG_BUTTONWAIT_GET    ;get value of WHDLoad option ButtonWait/S (0/-1)
  93.  EITEM    WHDLTAG_CUSTOM1_GET    ;get value of WHDLoad option Custom1/N (integer)
  94.  EITEM    WHDLTAG_CUSTOM2_GET    ;get value of WHDLoad option Custom2/N (integer)
  95.  EITEM    WHDLTAG_CUSTOM3_GET    ;get value of WHDLoad option Custom3/N (integer)
  96.  EITEM    WHDLTAG_CUSTOM4_GET    ;get value of WHDLoad option Custom4/N (integer)
  97.  EITEM    WHDLTAG_CUSTOM5_GET    ;get value of WHDLoad option Custom5/N (integer)
  98. ; version 7
  99.  EITEM    WHDLTAG_CBSWITCH_SET    ;set a function to be executed during switch
  100.                 ;from operating system to installed program
  101.  EITEM    WHDLTAG_CHIPREVBITS_GET    ;get info about current custom chip set
  102. ; version 8
  103.  EITEM    WHDLTAG_IOERR_GET    ;get last dos errorcode
  104.  EITEM    WHDLTAG_Private4
  105. ; version 9
  106.  EITEM    WHDLTAG_CBAF_SET    ;set a function to be executed when an access
  107.                 ;fault exception occurs
  108.  EITEM    WHDLTAG_VERSION_GET    ;get WHDLoad major version number
  109.  EITEM    WHDLTAG_REVISION_GET    ;get WHDLoad minor version number
  110.  EITEM    WHDLTAG_BUILD_GET    ;get WHDLoad build number
  111.  EITEM    WHDLTAG_TIME_GET    ;get current time and date
  112.  
  113. ;=============================================================================
  114. ;    structure returned by WHDLTAG_TIME_GET
  115. ;=============================================================================
  116.  
  117.     STRUCTURE whdload_time,0
  118.         ULONG    whdlt_days    ;days since 1.1.1978
  119.         ULONG    whdlt_mins    ;minutes since last day
  120.         ULONG    whdlt_ticks    ;1/50 seconds since last minute
  121.         UBYTE    whdlt_year    ;78..77 (1978..2077)
  122.         UBYTE    whdlt_month    ;1..12
  123.         UBYTE    whdlt_day    ;1..31
  124.         UBYTE    whdlt_hour    ;0..23
  125.         UBYTE    whdlt_min    ;0..59
  126.         UBYTE    whdlt_sec    ;0..59
  127.         LABEL    whdlt_SIZEOF
  128.  
  129. ;=============================================================================
  130. ; Slave        Version 1..3
  131. ;=============================================================================
  132.  
  133.     STRUCTURE    WHDLoadSlave,0
  134.     STRUCT    ws_Security,4
  135.     STRUCT    ws_ID,8        ;"WHDLOADS"
  136.     UWORD    ws_Version    ;required WHDLoad version
  137.     UWORD    ws_Flags    ;see below
  138.     ULONG    ws_BaseMemSize    ;size of required memory (multiple of $1000)
  139.     ULONG    ws_ExecInstall    ;must be 0
  140.     RPTR    ws_GameLoader    ;Slave code, called by WHDLoad
  141.     RPTR    ws_CurrentDir    ;subdirectory for data files
  142.     RPTR    ws_DontCache    ;pattern for files not to cache
  143.  
  144. ;=============================================================================
  145. ; additional    Version 4..7
  146. ;=============================================================================
  147.  
  148.     UBYTE    ws_keydebug    ;raw key code to quit with debug
  149.                 ;works only if vbr is moved !
  150.                 ;=0 means no key
  151.     UBYTE    ws_keyexit    ;raw key code to exit
  152.                 ;works only if vbr is moved !
  153.                 ;=0 means no key
  154.  
  155. ;=============================================================================
  156. ; additional    Version 8..9
  157. ;=============================================================================
  158.  
  159.     ULONG    ws_ExpMem    ;size of required expansions memory, during
  160.                 ;initialisation overwritten by WHDLoad with
  161.                 ;address of the memory (multiple of $1000)
  162.                 ;if negative it is optional
  163.  
  164. ;=============================================================================
  165. ; additional    Version 10
  166. ;=============================================================================
  167.  
  168.     RPTR    ws_name        ;name of the installed program
  169.     RPTR    ws_copy        ;year and owner of the copyright
  170.     RPTR    ws_info        ;additional informations (author, version...)
  171.     LABEL    ws_SIZEOF
  172.  
  173. ;=============================================================================
  174. ; Flags for ws_Flags
  175. ;=============================================================================
  176.  
  177.     BITDEF WHDL,Disk,0    ;means diskimages are used by the Slave
  178.                 ;starting WHDLoad 0.107 obsolete
  179.     BITDEF WHDL,NoError,1    ;forces WHDLoad to abort the installed program
  180.                 ;if error during resload_#? function occurs
  181.     BITDEF WHDL,EmulTrap,2    ;forward "trap #n" exceptions to the handler
  182.                 ;of the installed program
  183.     BITDEF WHDL,NoDivZero,3    ;ignore division by zero exceptions
  184. ; version 7
  185.     BITDEF WHDL,Req68020,4    ;abort if no MC68020 or better is available
  186.     BITDEF WHDL,ReqAGA,5    ;abort if no AGA chipset is available
  187. ; version 8
  188.     BITDEF WHDL,NoKbd,6    ;says WHDLoad that it doesn't should get the
  189.                 ;keycode from the keyboard in conjunction with
  190.                 ;NoVBRMove, must be used if the installed
  191.                 ;program checks the keyboard from the VBI
  192.     BITDEF WHDL,EmulLineA,7    ;forward "line-a" exceptions to the handler
  193.                 ;of the installed program
  194. ; version 9
  195.     BITDEF WHDL,EmulTrapV,8    ;forward "trapv" exceptions to the handler
  196.                 ;of the installed program
  197.  
  198. ;=============================================================================
  199. ; properties for resload_SetCPU
  200. ;=============================================================================
  201.  
  202. WCPUF_Base    = 3        ;BaseMem mask
  203. WCPUF_Base_NCS    = 0        ;BaseMem = non cacheable serialized
  204. WCPUF_Base_NC    = 1        ;BaseMem = non cacheable
  205. WCPUF_Base_WT    = 2        ;BaseMem = cacheable write trough
  206. WCPUF_Base_CB    = 3        ;BaseMem = cacheable copyback
  207. WCPUF_Exp    = 12        ;ExpMem mask
  208. WCPUF_Exp_NCS    = 0        ;ExpMem = non cacheable serialized
  209. WCPUF_Exp_NC    = 4        ;ExpMem = non cacheable
  210. WCPUF_Exp_WT    = 8        ;ExpMem = cacheable write trough
  211. WCPUF_Exp_CB    = 12        ;ExpMem = cacheable copyback
  212. WCPUF_Slave    = 48        ;Slave mask
  213. WCPUF_Slave_NCS    = 0        ;Slave = non cacheable serialized
  214. WCPUF_Slave_NC    = 16        ;Slave = non cacheable
  215. WCPUF_Slave_WT    = 32        ;Slave = cacheable write trough
  216. WCPUF_Slave_CB    = 48        ;Slave = cacheable copyback
  217.  
  218.     BITDEF WCPU,IC,8    ;instruction cache (20-60)
  219.     BITDEF WCPU,DC,9    ;data cache (30-60)
  220.     BITDEF WCPU,NWA,10    ;disable write allocation (30)
  221.     BITDEF WCPU,SB,11    ;store buffer (60)
  222.     BITDEF WCPU,BC,12    ;branch cache (60)
  223.     BITDEF WCPU,SS,13    ;superscalar dispatch (60)
  224.     BITDEF WCPU,FPU,14    ;enable fpu (60)
  225.  
  226. WCPUF_All    = WCPUF_Base!WCPUF_Exp!WCPUF_Slave!WCPUF_IC!WCPUF_DC!WCPUF_NWA!WCPUF_SB!WCPUF_BC!WCPUF_SS!WCPUF_FPU
  227.  
  228. ;=============================================================================
  229. ; resload_#? functions
  230. ; a JMP-tower inside WHDLoad (similar to a library)
  231. ; base is given on startup via A0
  232. ;=============================================================================
  233.  
  234.     STRUCTURE    ResidentLoader,0
  235.     ULONG    resload_Install        ;private
  236.     ULONG    resload_Abort
  237.         ; return to operating system
  238.         ; IN: (a7) = ULONG  reason for aborting
  239.         ;   (4,a7) = ULONG  primary error code
  240.         ;   (8,a7) = ULONG  secondary error code
  241.         ; ATTENTION this routine must called via JMP! (not JSR)
  242.     ULONG    resload_LoadFile
  243.         ; load file to memory
  244.         ; IN :    a0 = CPTR   filename
  245.         ;    a1 = APTR   address
  246.         ; OUT :    d0 = ULONG  success (size of file)
  247.         ;    d1 = ULONG  dos errorcode
  248.     ULONG    resload_SaveFile
  249.         ; write memory to file
  250.         ; IN :    d0 = LONG   size
  251.         ;    a0 = CPTR   filename
  252.         ;    a1 = APTR   address
  253.         ; OUT :    d0 = BOOL   success
  254.         ;    d1 = ULONG  dos errorcode
  255.     ULONG    resload_SetCACR
  256.         ; set cachebility for BaseMem
  257.         ; IN :    d0 = ULONG  new setup
  258.         ;    d1 = ULONG  mask
  259.         ; OUT :    d0 = ULONG  old setup
  260.     ULONG    resload_ListFiles
  261.         ; list filenames of directory
  262.         ; IN :    d0 = ULONG  buffer size
  263.         ;    a0 = CPTR   name of directory to scan
  264.         ;    a1 = APTR   buffer (must be located in Slave)
  265.         ; OUT :    d0 = ULONG  amount of names in buffer
  266.         ;    d1 = ULONG  dos errorcode
  267.     ULONG    resload_Decrunch
  268.         ; uncompress data in memory
  269.         ; IN :    a0 = APTR   source
  270.         ;    a1 = APTR   destination (can be equal to source)
  271.         ; OUT :    d0 = ULONG  uncompressed size
  272.     ULONG    resload_LoadFileDecrunch
  273.         ; load file and uncompress
  274.         ; IN :    a0 = CPTR   filename
  275.         ;    a1 = APTR   address
  276.         ; OUT :    d0 = ULONG  success (size of file)
  277.         ;    d1 = ULONG  dos errorcode
  278.     ULONG    resload_FlushCache
  279.         ; clear CPU caches
  280.         ; IN :    -
  281.         ; OUT :    -
  282.     ULONG    resload_GetFileSize
  283.         ; get size of file
  284.         ; IN :    a0 = CPTR   filename
  285.         ; OUT :    d0 = ULONG  size of file
  286.     ULONG    resload_DiskLoad
  287.         ; load part from diskimage
  288.         ; IN :    d0 = ULONG  offset
  289.         ;    d1 = ULONG  size
  290.         ;    d2 = ULONG  disk number
  291.         ;    a0 = APTR   destination
  292.         ; OUT :    d0 = BOOL   success
  293.         ;    d1 = ULONG  dos errorcode
  294.  
  295. ******* the following functions require ws_Version >= 2
  296.  
  297.     ULONG    resload_DiskLoadDev
  298.         ; IN :    d0 = ULONG  offset
  299.         ;    d1 = ULONG  size
  300.         ;    a0 = APTR   destination
  301.         ;    a1 = STRUCT taglist
  302.         ; OUT :    d0 = BOOL   success
  303.         ;    d1 = ULONG  trackdisk errorcode
  304.  
  305. ******* the following functions require ws_Version >= 3
  306.  
  307.     ULONG    resload_CRC16
  308.         ; calculate 16 bit CRC checksum
  309.         ; IN :    d0 = ULONG  size
  310.         ;    a0 = APTR   address
  311.         ; OUT :    d0 = UWORD  CRC checksum
  312.  
  313. ******* the following functions require ws_Version >= 5
  314.  
  315.     ULONG    resload_Control
  316.         ; IN :    a0 = STRUCT taglist
  317.         ; OUT :    d0 = BOOL   success
  318.     ULONG    resload_SaveFileOffset
  319.         ; write memory to file at offset
  320.         ; IN :    d0 = ULONG  size
  321.         ;    d1 = ULONG  offset
  322.         ;    a0 = CPTR   filename
  323.         ;    a1 = APTR   address
  324.         ; OUT :    d0 = BOOL   success
  325.         ;    d1 = ULONG  dos errcode
  326.  
  327. ******* the following functions require ws_Version >= 6
  328.  
  329.     ULONG    resload_ProtectRead
  330.         ; mark memory as read protected
  331.         ; IN :    d0 = ULONG  length
  332.         ;    a0 = CPTR   address
  333.         ; OUT :    -
  334.     ULONG    resload_ProtectReadWrite
  335.         ; mark memory as read and write protected
  336.         ; IN :    d0 = ULONG  length
  337.         ;    a0 = CPTR   address
  338.         ; OUT :    -
  339.     ULONG    resload_ProtectWrite
  340.         ; mark memory as write protected
  341.         ; IN :    d0 = ULONG  length
  342.         ;    a0 = CPTR   address
  343.         ; OUT :    -
  344.     ULONG    resload_ProtectRemove
  345.         ; remove memory protection
  346.         ; IN :    d0 = ULONG  length
  347.         ;    a0 = CPTR   address
  348.         ; OUT :    -
  349.     ULONG    resload_LoadFileOffset
  350.         ; load part of file to memory
  351.         ; IN :    d0 = ULONG  offset
  352.         ;    d1 = ULONG  size
  353.         ;    a0 = CPTR   name of file
  354.         ;    a1 = APTR   destination
  355.         ; OUT :    d0 = BOOL   success
  356.         ;    d1 = ULONG  dos errorcode
  357.  
  358. ******* the following functions require ws_Version >= 8
  359.  
  360.     ULONG    resload_Relocate
  361.         ; relocate AmigaDOS executable
  362.         ; IN :    a0 = APTR   address (source=destination)
  363.         ;    a1 = STRUCT taglist
  364.         ; OUT :    d0 = ULONG  size
  365.     ULONG    resload_Delay
  366.         ; wait some time
  367.         ; IN :    d0 = ULONG  time to wait in 1/10 seconds
  368.         ; OUT :    -
  369.     ULONG    resload_DeleteFile
  370.         ; delete file
  371.         ; IN :    a0 = CPTR   filename
  372.         ; OUT :    d0 = BOOL   success
  373.         ;    d1 = ULONG  dos errorcode
  374.  
  375. ******* the following functions require ws_Version >= 10
  376.  
  377.     ULONG    resload_ProtectSMC
  378.         ; detect self modifying code
  379.         ; IN :    d0 = ULONG  length
  380.         ;    a0 = CPTR   address
  381.         ; OUT :    -
  382.     ULONG    resload_SetCPU
  383.         ; control CPU setup
  384.         ; IN :    d0 = ULONG  properties
  385.         ;    d1 = ULONG  mask
  386.         ; OUT :    d0 = ULONG  old properties
  387.     ULONG    resload_Patch
  388.         ; apply patchlist
  389.         ; IN :    a0 = APTR   patchlist
  390.         ;    a1 = APTR   destination address
  391.         ; OUT :    -
  392.  
  393.     LABEL    resload_SIZEOF
  394.  
  395. ******* compatibility for older slave sources:
  396.  
  397. resload_CheckFileExist = resload_GetFileSize
  398.  
  399. ;=============================================================================
  400. ; commands used in patchlist
  401. ; each command follows the address to modify, if bit 16 of the command is
  402. ; cleared address follows as 32 bit, if bit 16 of the command is set it
  403. ; follows as 16 bit (unsigned extended to 32 bit)
  404.  
  405.     ENUM    0
  406.     EITEM    PLCMD_END        ;end of list
  407.     EITEM    PLCMD_R            ;set "rts"
  408.     EITEM    PLCMD_P            ;set "jmp"
  409.     EITEM    PLCMD_PS        ;set "jsr"
  410.     EITEM    PLCMD_S            ;set "bra.w" (skip)
  411.     EITEM    PLCMD_I            ;set "illegal"
  412.     EITEM    PLCMD_B            ;write byte to specified address
  413.     EITEM    PLCMD_W            ;write word to specified address
  414.     EITEM    PLCMD_L            ;write long to specified address
  415.  
  416. ;=============================================================================
  417. ; macros to build patchlist
  418.  
  419. PL_START    MACRO            ;start of patchlist
  420. .patchlist
  421.         ENDM
  422.  
  423. PL_END        MACRO            ;end of patchlist
  424.     dc.w    PLCMD_END
  425.         ENDM
  426.  
  427. PL_CMDADR    MACRO            ;set cmd and address
  428.     IFLT $ffff-\2
  429.     dc.w    \1
  430.     dc.l    \2
  431.     ELSE
  432.     dc.w    $8000+\1
  433.     dc.w    \2
  434.     ENDC
  435.     ENDM
  436.  
  437. PL_R        MACRO            ;set "rts"
  438.     PL_CMDADR PLCMD_R,\1
  439.         ENDM
  440.  
  441. PL_PS        MACRO            ;set "jmp"
  442.     PL_CMDADR PLCMD_PS,\1
  443.     dc.w    \2-.patchlist        ;destination (inside slave!)
  444.         ENDM
  445.  
  446. PL_P        MACRO            ;set "jsr"
  447.     PL_CMDADR PLCMD_P,\1
  448.     dc.w    \2-.patchlist        ;destination (inside slave!)
  449.         ENDM
  450.  
  451. PL_S        MACRO            ;skip bytes, set "bra"
  452.     PL_CMDADR PLCMD_S,\1
  453.     dc.w    \2-2            ;distance
  454.         ENDM
  455.  
  456. PL_I        MACRO            ;set "illegal"
  457.     PL_CMDADR PLCMD_I,\1
  458.         ENDM
  459.  
  460. PL_B        MACRO            ;write byte
  461.     PL_CMDADR PLCMD_B,\1
  462.     dc.w    \2            ;data to write
  463.         ENDM
  464.  
  465. PL_W        MACRO            ;write word
  466.     PL_CMDADR PLCMD_W,\1
  467.     dc.w    \2            ;data to write
  468.         ENDM
  469.  
  470. PL_L        MACRO            ;write long
  471.     PL_CMDADR PLCMD_L,\1
  472.     dc.l    \2            ;data to write
  473.         ENDM
  474.  
  475. ;=============================================================================
  476.  
  477.  ENDC
  478.